﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
using HRM.DICTIONARY.BLL;

namespace HRM.DICTIONARY.DATABASEUI
{
    public partial class xfrmRestoreDatabase : DevExpress.XtraEditors.XtraForm
    {
        public xfrmRestoreDatabase()
        {
            InitializeComponent();
            txtBackupFolder.Text = @"C:\Backup";

        }

        private void txtBackupFile_Properties_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog
            {
                Filter = "Backup File(*.bak)|*.bak|All File(*.*)|*.*",
                FilterIndex = 0
            };
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.txtBackupFile.Text = dialog.FileName;
            }
        }
        protected override bool ProcessDialogKey(System.Windows.Forms.Keys keyData)
        {
            if (keyData == System.Windows.Forms.Keys.Escape)
            {
                base.Close();
                return true;
            }
            return false;
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            this.btnStart.Enabled = false;
            DataController restore = new DataController();
            restore.progess = Bar;
            this.groupControl1.Text = "Đang Phục Hồi...";
            bool KQ = restore.RestoreDatabase( this.txtBackupFile.Text, "toro.hrm");
            XtraMessageBox.Show(restore.ErrMsg, "Thông Báo");
        }

        private void txtBackupFolder_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog
            {
                Filter = "Backup File(*.bak)|*.bak|All File(*.*)|*.*",
                FilterIndex = 0
            };
            dialog.InitialDirectory = @"C:\Backup";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.txtBackupFile.Text = dialog.FileName;
            }
        }
    }
}